package com.atguigu.mycloud.exception;

import com.atguigu.mycloud.Enum.ReturnCodeEnum;
import com.atguigu.mycloud.Enum.ReturnMessage;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author 任浩
 * @version 1.0
 */

@Slf4j
@RestControllerAdvice  //开启全局异常捕获。
public class GlobalExceptionHandler {

    @ExceptionHandler(RuntimeException.class)  //表示检测在运行时出错的异常。
    public ReturnMessage<String> golbalException(Exception e){
        log.error("全局异常信息：" + e.getMessage(),e);
        return ReturnMessage.fail(ReturnCodeEnum.RC500.getCode(), ReturnCodeEnum.RC500.getMessage());
    }
}
